import { http } from "@/utils/http";
import type { OperationLogItem } from "@/views/monitor/logs/operation/types";

type Result = {
  [x: string]: any;
  name?: String;
  data?: Array<any>;
};

type ResultTable = {
  /** 列表数据 */
  list: Array<any>;
  /** 总条目数 */
  total?: number;
  /** 每页显示条目个数 */
  pageSize?: number;
  /** 当前页数 */
  currentPage?: number;
};

/** 获取系统管理-用户管理列表 */
export const getUserList = (data?: object) => {
  return http.request<ResultTable>("post", "/api/private/user", { data });
};
/** 用户管理-修改用户 */
export const editUser = (data?: object) => {
  return http.request<Result>("post", "/api/private/user/edit", { data });
};
/** 用户管理-删除用户 */
export const deleteUser = (data?: object) => {
  return http.request<Result>("post", "/api/private/user/delete", { data });
};
/** 用户管理-新增用户 */
export const addUser = (data?: object) => {
  return http.request<Result>("post", "/api/private/user/add", { data });
};
/** 用户管理-修改密码 */
export const editPassword = (data?: object) => {
  return http.request<Result>("post", "/api/private/user/password", { data });
};

/** 系统管理-用户管理-获取所有角色列表 */
export const getAllRoleList = () => {
  return http.request<Result[]>("get", "/api/private/role/list");
};

/** 系统管理-用户管理-根据userId，获取对应角色id列表（userId：用户id） */
export const getRoleIds = (data?: object) => {
  return http.request<Result>("post", "/api/private/user/role", { data });
};
/** 系统管理-用户管理-角色保存 */
export const saveUserRole = (data?: object) => {
  return http.request<Result>("post", "/api/private/user/role/save", { data });
};

/** 获取系统管理-角色管理列表 */
export const getRoleList = (data?: object) => {
  return http.request<ResultTable>("post", "/api/private/role", { data });
};

/** 角色管理-新增角色 */
export const addRole = (data?: object) => {
  return http.request<Result>("post", "/api/private/role/add", { data });
};

/** 角色管理-修改角色 */
export const editRole = (data?: object) => {
  return http.request<Result>("post", "/api/private/role/edit", { data });
};

/** 角色管理-删除角色 */
export const deleteRole = (data?: object) => {
  return http.request<Result>("post", "/api/private/role/delete", { data });
};

/** 获取系统管理-菜单管理列表 */
export const getMenuList = (data?: object) => {
  return http.request<ResultTable>("post", "/api/private/menu", { data });
};

/** 菜单管理-新增菜单 */
export const addMenu = (data?: object) => {
  return http.request<Result>("post", "/api/private/menu/add", { data });
};

/** 菜单管理-修改菜单 */
export const editMenu = (data?: object) => {
  return http.request<Result>("post", "/api/private/menu/edit", { data });
};

/** 菜单管理-删除菜单 */
export const deleteMenu = (data?: object) => {
  return http.request<Result>("post", "/api/private/menu/delete", { data });
};

/** 获取系统管理-部门管理列表 */
export const getDeptList = (data?: object) => {
  return http.request<Result[]>("post", "/api/private/dept", { data });
};

/** 部门管理-新增部门 */
export const addDept = (data?: object) => {
  return http.request<Result>("post", "/api/private/dept/add", { data });
};
/** 部门管理-修改部门 */
export const editDept = (data?: object) => {
  return http.request<Result>("post", "/api/private/dept/edit", { data });
};

/** 部门管理-删除部门 */
export const deleteDept = (data?: object) => {
  return http.request<Result>("post", "/api/private/dept/delete", { data });
};

/** 获取系统监控-在线用户列表 */
export const getOnlineLogsList = (data?: object) => {
  return http.request<Result[]>("post", "/api/private/logs/online", {
    data
  });
};
/** 在线用户列表-强制退线 */
export const forceLogout = (data?: object) => {
  return http.request<Result>("post", "/api/private/logs/online/force", {
    data
  });
};

/** 获取系统监控-登录日志列表 */
export const getLoginLogsList = (data?: object) => {
  return http.request<ResultTable>("post", "/api/private/logs/login-log", {
    data
  });
};
/** 删除登录日志 */
export const deleteLoginLogs = (data?: object) => {
  return http.request<Result>("post", "/api/private/logs/login-log/delete", {
    data
  });
};

/** 获取系统监控-系统附件列表 */
export const getFileList = (data?: object) => {
  return http.request<ResultTable>("post", "/api/private/files", { data });
};

/** 删除系统附件 */
export const deleteFile = (data?: object) => {
  return http.request<Result>("post", "/api/private/files/delete", { data });
};

/** 获取系统监控-系统日志列表 */
export const getSystemLogs = (data?: object) => {
  return http.request<Result>("get", "/api/private/logs/system", { data });
};

/** 获取系统监控-系统日志-根据 id 查日志详情 */
export const getSystemLogsDetail = (data?: object) => {
  return http.request<Result>("post", "/api/private/logs/system/detail", {
    data
  });
};
/** 删除系统日志 */
export const deleteSystemLogs = (data?: object) => {
  return http.request<Result>("post", "/api/private/logs/system/delete", {
    data
  });
};
/** 获取操作日志列表 */
export const getOperationLogsList = (data?: object) => {
  return http.request<ResultTable>("post", "/api/private/logs/operation-log", {
    data
  });
};
/** 操作日志 - 根据 id 查日志详情 */
export const getOperationLogsDetail = (data?: object) => {
  return http.request<OperationLogItem>(
    "post",
    "/api/private/logs/operation-log/detail",
    {
      data
    }
  );
};
/** 获取角色管理-权限-菜单权限 */
export const getRoleMenu = (data?: object) => {
  return http.request<Result[]>("get", "/api/private/menu/list", { data });
};

/** 获取角色管理-权限-菜单权限-根据角色 id 查对应菜单 */
export const getRoleMenuIds = (data?: object) => {
  return http.request<Result>("post", "/api/private/role/menus", { data });
};

/** 角色管理-权限-菜单权限-保存 */
export const saveRoleMenu = (data?: object) => {
  return http.request<Result>("post", "/api/private/role/menus/save", { data });
};

/** 获取系统通知列表 */
export const getMessage = (type, data?: object) => {
  return http.request<Result>("post", `/api/private/notice/list/${type}`, {
    data
  });
};
/** 未读通知-分类 */
export const unreadMessage = (data?: object) => {
  return http.request<Result>("get", "/api/private/notice/unread", { data });
};

/** 已读通知 */
export const readMessage = id => {
  return http.request<Result>("get", `/api/private/notice/read/${id}`);
};
/** 删除通知 */
export const deleteNotice = (data?: object) => {
  return http.request<Result>("post", "/api/private/notice/delete", { data });
};
